<?php

namespace Api\Openapi;


use S\Http;

class Econtract {

    const URI_SIGN = "/econtract/sign";
    const URI_QUERY_SIGN_RESULT = "/econtract/query";

    /**
     * 通用-合同签订接口（异步）
     *
     * @param $service_id
     * @param $name
     * @param $mobile
     * @param array $contract
     * @param $trans_id
     * @param null $cert_type
     * @param null $cert_no
     * @param null $address
     * @param int $timeout
     *
     * @return string|bool
     */
    public function sign($service_id, $name, $mobile, array $contract, $trans_id = null, $cert_type = null, $cert_no = null, $address = null, $timeout = Http::TIMEOUT){
        $body = array(
            "service_id" => $service_id,
            "name" => $name,
            "mobile" => $mobile,
            "contract" => $contract,
        );
        if (!empty($trans_id)) {
            $body["trans_id"] = $trans_id;
        }
        if (!empty($cert_type) && !empty($cert_no)) {
            $body["cert_type"] = $cert_type;
            $body["cert_no"] = $cert_no;
        }
        if (!empty($trans_id)) {
            $body["address"] = $address;
        }
        $params = array(
            "header" => array(),
            "body" => $body,
        );

        return Util::request(self::URI_SIGN, $params, $timeout)["body"];
    }

    /**
     * 通用-合同签订接口（异步）
     *
     * @param $service_id
     * @param $trans_id
     * @param int $timeout
     *
     * @return array
     */
    public function getSignResult($service_id, $trans_id, $timeout = Http::TIMEOUT){
        $params = array(
            "header" => array(),
            "body" => array(
                "service_id" => $service_id,
                "trans_id" => $trans_id,
            ),
        );

        return Util::request(self::URI_QUERY_SIGN_RESULT, $params, $timeout)["body"];
    }

} 